<!-- 考核标准管理 -->
<style lang="less">
.ass-stand {
  .ivu-card-body {
    padding: 0px;
  }
}
</style>


<template>
  <div class="ass-stand">
    <Card :bordered="false">
      <p slot="title">考核标准管理 > <span class="select-font">考核标准</span>
      </p>
    </Card>
    <div class="">
      <Table :data="assData"
             :columns="assColumns"
             stripe></Table>
      <Modal v-model="moduleModal"
             width="400"
             title="修改考核标准"
             :mask-closable="false"
             @on-ok="ok">
        <Form :model="assItem"
              :label-width="80">
          <Form-item label="有效次数"
                     prop="num">
            <Input v-model="assItem.num"
                   :maxlength="3"
                   placeholder="请输入有效次数"></Input>
          </Form-item>
          <Form-item label="间隔天数"
                     prop="day">
            <Input v-model="assItem.day"
                   :maxlength="3"
                   placeholder="请输入间隔天数"></Input>
          </Form-item>
        </Form>
      </Modal>
    </div>
  </div>
</template>


<script>
import { ajaxPost } from 'global/axios';
import storage from 'good-storage';
export default {
  data() {
    return {
      urlAssList: '/sys/assess/list',
      urlAssEdit: '/sys/assess/edit',
      assData: [],
      assColumns: [
        {
          title: '河长级别',
          align: 'center',
          key: 'rolename',
        },
        {
          title: '有效次数',
          align: 'center',
          render: (h, params) => {
            if (params.index > 5) {
              return params.row.patrol ? params.row.patrol.num : null;
            } else {
              return params.row.checkin ? params.row.checkin.num : null;
            }
          },
        },
        {
          title: '间隔天数',
          align: 'center',
          render: (h, params) => {
            if (params.index > 5) {
              return params.row.patrol ? params.row.patrol.day : null;
            } else {
              return params.row.checkin ? params.row.checkin.day : null;
            }
          },
        },
        {
          title: '操作',
          align: 'center',
          render: (h, params) => {
            if (params.row.patrol) {
              return h('div', [
                h(
                  'Button',
                  {
                    props: {
                      type: 'primary',
                      size: 'small',
                    },
                    style: {
                      marginRight: '5px',
                    },
                    on: {
                      click: () => {
                        this.edit(params.row, params.index);
                      },
                    },
                  },
                  '编辑'
                ),
              ]);
            }
          },
        },
      ],
      moduleModal: false,
      assItem: {},
      saveRow: {},
      saveIndex: '',
    };
  },
  methods: {
    getTableData(page = 1) {
      let params = {
        data: {
          pageSize: 10,
          page,
        },
        url: this.urlAssList,
        token: storage.session.get('token'),
        success: res => {
          this.$Loading.finish();
          this.assData = res.data.result;
        },
      };
      ajaxPost(params);
    },
    ok() {
      if (this.saveIndex > 5) {
        this.saveRow.patrol.day = this.assItem.day;
        this.saveRow.patrol.num = this.assItem.num;
      } else {
        this.saveRow.checkin.day = this.assItem.day;
        this.saveRow.checkin.num = this.assItem.num;
      }
      let params = {
        data: this.saveRow,
        url: this.urlAssEdit,
        token: storage.session.get('token'),
        success: res => {
          if (res.data.code == '0000') {
            this.$Loading.finish();
            this.$Message.success({
              content: '修改成功',
            });
            this.moduleModal = false;
            this.getTableData();
          } else {
            this.$Message.warning({
              content: res.data.message,
            });
          }
        },
      };
      ajaxPost(params);
    },
    edit(row, index) {
      this.saveRow = row;
      this.saveIndex = index;
      this.assItem = {
        num: '',
        day: '',
      };
      this.moduleModal = true;
      if (index > 5) {
        this.assItem.num = row.patrol.num;
        this.assItem.day = row.patrol.day;
      } else {
        this.assItem.num = row.checkin.num;
        this.assItem.day = row.checkin.day;
      }
    },
  },
  mounted() {
    this.getTableData();
  },
};
</script>
